﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
    
namespace SimulationPresenter.Presentation.Helpers
{
    /// <summary>
    /// Extensions for Matrix struct
    /// </summary>
    public static class MatrixExtensions
    {
        /// <summary>
        /// Creates matrix from float[16]
        /// </summary>
        /// <param name="input"></param>
        /// <param name="matrix"></param>
        /// <returns></returns>
        public static Matrix FromFloat16(this Matrix matrix, float[][] input)
        {
            if (input.Length != 4)
            {
                throw new ArgumentOutOfRangeException("input", "Input array should have exactly 16 elements.");
            }

            //Set matrix values
            matrix.M11 = input[0][0];
            matrix.M12 = input[0][1];
            matrix.M13 = input[0][2];
            matrix.M14 = input[0][3];
            matrix.M21 = input[1][0];
            matrix.M22 = input[1][1];
            matrix.M23 = input[1][2];
            matrix.M24 = input[1][3];
            matrix.M31 = input[2][0];
            matrix.M32 = input[2][1];
            matrix.M33 = input[2][2];
            matrix.M34 = input[2][3];
            matrix.M41 = input[3][0];
            matrix.M42 = input[3][1];
            matrix.M43 = input[3][2];
            matrix.M44 = input[3][3];

            return matrix;
        }
    }
}
